package com.itlong.cloud.controller.system;

import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.PropertyUiInfoVO;
import com.itlong.cloud.enumerate.PropertyEquipTypeEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.noncore.property.IPropertyUiServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      物业-UI管理。
 * <desc/>
 *
 * @createDate 2018-03-28.
 */
@RestController
@RequestMapping("/system/user")
public class PropertyUiManageController {

    @Autowired
    IPropertyUiServiceClient iPropertyUiServiceClient;
    /**
     * <desc>
     *      获取UI信息。
     * <desc/>
     *
     * @param projectId
     * @return
     * @author shengen.T
     * @createDate 2018-03-28
     */
    @PostMapping(path = "getUiInfo")
    @ResponseBody
    public Object gePropertyUiInfo(String projectId){
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            //判断项目编号
            if(StringUtils.isBlank(projectId) || (!projectId.matches("[0-9]{8}"))){
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_IS_ILLEGAL.getErrorCode());
            }
            PropertyUiInfoVO oneVO = iPropertyUiServiceClient.getUiInfo(projectId);
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),oneVO);
        }catch (Exception e){
            throw new DataAccessException("【物业_UI管理_获取getOne】获取UI信息失败",e);
        }
        return messageVO;
    }
}
